package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;


@WebServlet("/demo5")
public class ServletDemo5 extends HttpServlet {
    //输入流对象获取数据
    //只有post请求的方式才能获取字符流数据


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //字符流（必须是post提交方式）获取数据   掌握

        BufferedReader br = req.getReader();
        String len;
        while ((len = br.readLine()) != null) {
            System.out.println(len);
        }


        //字节流       获取数据
        ServletInputStream is = req.getInputStream();

        int line;
        byte[] bytes = new byte[1024];
        while ((line = is.read(bytes)) != -1) {
            System.out.println(new String(bytes,0,line));
        }

    }
}
